<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  
  
  <title>内网穿透 | 花椒茴香的博客</title>
  <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
  <meta name="description" content="之前使用花生壳来进行内网穿透，只能穿透一个，相当于没有，然后发现了frp这个神仙项目。 frp可以通过一个有公网IP的服务器来进行转发，服务器启动frps，内网机器启动frps，然后就可以访问内网机器啦。 搭建过程硬件条件Jetson Nano B01 ，阿里云服务器一台，域名一个。 下载frp首先下载frp项目，https:&#x2F;&#x2F;github.com&#x2F;fatedier&#x2F;frp&#x2F;releases，阿">
<meta property="og:type" content="article">
<meta property="og:title" content="内网穿透">
<meta property="og:url" content="http://huajiaohuixiang.gitee.io/2021/10/25/%E5%86%85%E7%BD%91%E7%A9%BF%E9%80%8F/index.html">
<meta property="og:site_name" content="花椒茴香的博客">
<meta property="og:description" content="之前使用花生壳来进行内网穿透，只能穿透一个，相当于没有，然后发现了frp这个神仙项目。 frp可以通过一个有公网IP的服务器来进行转发，服务器启动frps，内网机器启动frps，然后就可以访问内网机器啦。 搭建过程硬件条件Jetson Nano B01 ，阿里云服务器一台，域名一个。 下载frp首先下载frp项目，https:&#x2F;&#x2F;github.com&#x2F;fatedier&#x2F;frp&#x2F;releases，阿">
<meta property="og:locale" content="en_US">
<meta property="article:published_time" content="2021-10-25T07:09:04.000Z">
<meta property="article:modified_time" content="2021-11-24T14:51:47.208Z">
<meta property="article:author" content="John Doe">
<meta property="article:tag" content="网络">
<meta property="article:tag" content="frp">
<meta name="twitter:card" content="summary">
  
    <link rel="alternate" href="/atom.xml" title="花椒茴香的博客" type="application/atom+xml">
  
  
    <link rel="shortcut icon" href="/favicon.png">
  
  
    
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/typeface-source-code-pro@0.0.71/index.min.css">

  
  
<link rel="stylesheet" href="/css/style.css">

  
    
<link rel="stylesheet" href="/fancybox/jquery.fancybox.min.css">

  
<meta name="generator" content="Hexo 5.4.0"></head>

<body>
  <div id="container">
    <div id="wrap">
      <header id="header">
  <div id="banner"></div>
  <div id="header-outer" class="outer">
    <div id="header-title" class="inner">
      <h1 id="logo-wrap">
        <a href="/" id="logo">花椒茴香的博客</a>
      </h1>
      
    </div>
    <div id="header-inner" class="inner">
      <nav id="main-nav">
        <a id="main-nav-toggle" class="nav-icon"></a>
        
          <a class="main-nav-link" href="/">Home</a>
        
          <a class="main-nav-link" href="/archives">Archives</a>
        
      </nav>
      <nav id="sub-nav">
        
          <a id="nav-rss-link" class="nav-icon" href="/atom.xml" title="RSS Feed"></a>
        
        <a id="nav-search-btn" class="nav-icon" title="Search"></a>
      </nav>
      <div id="search-form-wrap">
        <form action="//google.com/search" method="get" accept-charset="UTF-8" class="search-form"><input type="search" name="q" class="search-form-input" placeholder="Search"><button type="submit" class="search-form-submit">&#xF002;</button><input type="hidden" name="sitesearch" value="http://huajiaohuixiang.gitee.io"></form>
      </div>
    </div>
  </div>
</header>

      <div class="outer">
        <section id="main"><article id="post-内网穿透" class="h-entry article article-type-post" itemprop="blogPost" itemscope itemtype="https://schema.org/BlogPosting">
  <div class="article-meta">
    <a href="/2021/10/25/%E5%86%85%E7%BD%91%E7%A9%BF%E9%80%8F/" class="article-date">
  <time class="dt-published" datetime="2021-10-25T07:09:04.000Z" itemprop="datePublished">2021-10-25</time>
</a>
    
  </div>
  <div class="article-inner">
    
    
      <header class="article-header">
        
  
    <h1 class="p-name article-title" itemprop="headline name">
      内网穿透
    </h1>
  

      </header>
    
    <div class="e-content article-entry" itemprop="articleBody">
      
        <p>之前使用花生壳来进行内网穿透，只能穿透一个，相当于没有，然后发现了frp这个神仙项目。</p>
<p>frp可以通过一个有公网IP的服务器来进行转发，服务器启动frps，内网机器启动frps，然后就可以访问内网机器啦。</p>
<h4 id="搭建过程"><a href="#搭建过程" class="headerlink" title="搭建过程"></a>搭建过程</h4><h6 id="硬件条件"><a href="#硬件条件" class="headerlink" title="硬件条件"></a>硬件条件</h6><p>Jetson Nano B01 ，阿里云服务器一台，域名一个。</p>
<h6 id="下载frp"><a href="#下载frp" class="headerlink" title="下载frp"></a>下载frp</h6><p>首先下载frp项目，<a target="_blank" rel="noopener" href="https://github.com/fatedier/frp/releases%EF%BC%8C%E9%98%BF%E9%87%8C%E4%BA%91%E6%9C%8D%E5%8A%A1%E5%99%A8%E5%BA%94%E8%AF%A5%E6%98%AF%E8%A6%81%E4%B8%8B%E8%BD%BDfrp_0.36.2_linux_amd64.tar.gz%EF%BC%8C%E7%84%B6%E5%90%8E%E8%A7%A3%E5%8E%8B%E3%80%82Jetson">https://github.com/fatedier/frp/releases，阿里云服务器应该是要下载frp_0.36.2_linux_amd64.tar.gz，然后解压。Jetson</a> nano需要下载frp_0.36.2_linux_arm.tar.gz，然后解压。</p>
<h6 id="观察frp配置文件"><a href="#观察frp配置文件" class="headerlink" title="观察frp配置文件"></a>观察frp配置文件</h6><p>里面一共有一个systemd文件夹和frpc、frpc.ini、frpc_full.ini、frps、frps.ini、frps_full.ini。systemd先不用管，后面才会用到。</p>
<p>其中frpc和frps是两个启动程序。其余四个ini分别是启动程序的简单配置例子和详细配置例子。</p>
<h6 id="实现ssh"><a href="#实现ssh" class="headerlink" title="实现ssh"></a>实现ssh</h6><p>如果要实现ssh ，服务器和内网机器分别要进行以下配置。</p>
<p>服务器需要配置frps.ini文件，其实不用变哈哈，本来就是这样。</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">[common]</span><br><span class="line">bind_port = 7000</span><br></pre></td></tr></table></figure>

<p>然后内网机器需要进行一哈配置frpc.ini</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br></pre></td><td class="code"><pre><span class="line">[common]</span><br><span class="line">#这个是服务器的公网IP地址</span><br><span class="line">server_addr = 127.0.0.1</span><br><span class="line">#这个是服务器的监听端口，需要和服务器配置文件中的bind_port相同</span><br><span class="line">server_port = 7000</span><br><span class="line"></span><br><span class="line">#下面的ssh配置</span><br><span class="line">[ssh]</span><br><span class="line">#类型是tcp</span><br><span class="line">type = tcp</span><br><span class="line"></span><br><span class="line">#本地ip地址，可以是192.168.1.xxx这种，如果是127.0.0.1就是本机</span><br><span class="line">local_ip = 127.0.0.1、</span><br><span class="line"></span><br><span class="line">#本地端口</span><br><span class="line">local_port = 22</span><br><span class="line"></span><br><span class="line">#服务器端口，我们连接的时候连接服务器的6000端口就好了</span><br><span class="line">remote_port = 6000</span><br></pre></td></tr></table></figure>

<h6 id="实现http"><a href="#实现http" class="headerlink" title="实现http"></a>实现http</h6><p>服务器的frps.ini配置</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">[common]</span><br><span class="line">bind_port = 7000</span><br><span class="line"></span><br><span class="line">#表示用10000来监听http</span><br><span class="line">vhost_http_port = 10000  </span><br></pre></td></tr></table></figure>

<p>本地的frpc.ini配置</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line">[common]</span><br><span class="line">server_addr = x.x.x.x  </span><br><span class="line">server_port = 7000</span><br><span class="line"></span><br><span class="line">[web]</span><br><span class="line">type = http</span><br><span class="line">local_port = 10000</span><br><span class="line">custom_domains = 你的域名1或者ip地址</span><br><span class="line"></span><br><span class="line">[web2]</span><br><span class="line">type = http</span><br><span class="line">local_port = 100001</span><br><span class="line">custom_domains = 你的域名2或者ip地址</span><br></pre></td></tr></table></figure>

<p>因为每个web中的custom_domains都必须不同，如果直接写服务器的公网ip的话，只能实现一个http的转发，如果你有域名的话，是可以创建很多子域名，因此可以实现很多http转发。只需要在本地机器的frpc.ini中增加local_port和custon_domains即可。</p>
<h6 id="将其注册成服务"><a href="#将其注册成服务" class="headerlink" title="将其注册成服务"></a>将其注册成服务</h6><p>我是看着这个教程做的<a target="_blank" rel="noopener" href="https://blog.csdn.net/fjh1997/article/details/103672631%EF%BC%8C%E4%BD%86%E6%98%AF%E6%96%87%E4%B8%AD%E5%BA%94%E8%AF%A5%E6%98%AF%E6%9C%89%E4%B8%80%E4%B8%AA%E9%94%99%E8%AF%AF%EF%BC%8C%E2%80%9C%E6%88%91%E4%BB%AC%E6%8A%8A%E4%B8%8B%E8%BD%BD%E5%A5%BD%E7%9A%84%E6%89%80%E6%9C%89*.ini%E6%96%87%E4%BB%B6%E6%94%BE%E5%88%B0/etc/frpc/%E7%9B%AE%E5%BD%95%E4%B8%8B%E2%80%9D%EF%BC%8C%E5%9B%A0%E4%B8%BAfrpc@.service%E4%B8%AD%E7%9A%84%E8%B7%AF%E5%BE%84%E6%98%AF">https://blog.csdn.net/fjh1997/article/details/103672631，但是文中应该是有一个错误，“我们把下载好的所有*.ini文件放到/etc/frpc/目录下”，因为frpc@.service中的路径是</a> /etc/frp 所以应该放在 /etc/frp下。如果放在了frpc下需要改一下service中的路径。</p>
<p>还记得之前的systemd文件夹吗，那个就是注册成服务用的。</p>
<p>cd systemd进入文件夹 ls</p>
<p>一共有四个文件 frpc.service 和 frpc@.service还有frps的，带@和不带@的区别就是带@可以在启动服务的时候指定配置文件，不带@的只能使用文件中固定的配置文件</p>
<p>下面是frpc@.service的内容</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line">[Unit]</span><br><span class="line">Description=Frp Client Service</span><br><span class="line">After=network.target</span><br><span class="line"></span><br><span class="line">[Service]</span><br><span class="line">Type=idle</span><br><span class="line">User=nobody</span><br><span class="line">Restart=on-failure</span><br><span class="line">RestartSec=5s</span><br><span class="line">ExecStart=/usr/bin/frpc -c /etc/frp/%i.ini    #重点</span><br><span class="line">ExecReload=/usr/bin/frpc reload -c /etc/frp/%i.ini			#重点</span><br><span class="line"></span><br><span class="line">[Install]</span><br><span class="line">WantedBy=multi-user.target</span><br></pre></td></tr></table></figure>

<p>比较重要的就是这两个</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">ExecStart=/usr/bin/frpc -c /etc/frp/%i.ini   </span><br><span class="line">#这两个分别是frpc的路径和 frpc.ini的路径，其中frpc.ini通过%i实现了实时替换</span><br></pre></td></tr></table></figure>

<p>所以我们重点就是将 frpc 移动到 /usr/bin/下 ， 将 frpc.ini移动带 /etc/frp/下 ， 将frpc@.service移动到/etc/systemd/system/下。</p>
<p>然后通过</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">systemctl enable frpc@frpc  #这步用来注册服务     第一个frpc表示在/etc/systemd/system/下的frpc@.service，第二个frpc表示配置文件的前缀</span><br><span class="line">systemctl start frpc@frpc   #这步用来启动服务 通过x@x来表示 </span><br><span class="line">systemctl restart frpc@test  #如果我想更改配置，那么可以在/etc/frp/下创建test.ini，然后通过这个重新启动。</span><br></pre></td></tr></table></figure>

<p>对于frps也一样哦，移动三个文件，然后注册服务、启动，大功告成啦。</p>

      
    </div>
    <footer class="article-footer">
      <a data-url="http://huajiaohuixiang.gitee.io/2021/10/25/%E5%86%85%E7%BD%91%E7%A9%BF%E9%80%8F/" data-id="ckvf4x3n20007okv15txqceuy" data-title="内网穿透" class="article-share-link">Share</a>
      
      
      
  <ul class="article-tag-list" itemprop="keywords"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/frp/" rel="tag">frp</a></li><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/%E7%BD%91%E7%BB%9C/" rel="tag">网络</a></li></ul>

    </footer>
  </div>
  
    
<nav id="article-nav">
  
    <a href="/2021/10/25/Jetson%E5%AE%89%E8%A3%85Mysql/" id="article-nav-newer" class="article-nav-link-wrap">
      <strong class="article-nav-caption">Newer</strong>
      <div class="article-nav-title">
        
          Jetson安装Mysql
        
      </div>
    </a>
  
  
    <a href="/2021/10/25/%E7%BD%97%E7%94%9F%E9%97%A8/" id="article-nav-older" class="article-nav-link-wrap">
      <strong class="article-nav-caption">Older</strong>
      <div class="article-nav-title">罗生门</div>
    </a>
  
</nav>

  
</article>


</section>
        
          <aside id="sidebar">
  
    

  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Tags</h3>
    <div class="widget">
      <ul class="tag-list" itemprop="keywords"><li class="tag-list-item"><a class="tag-list-link" href="/tags/JetsonNano/" rel="tag">JetsonNano</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Kinect/" rel="tag">Kinect</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/frp/" rel="tag">frp</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/hexo/" rel="tag">hexo</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/linux/" rel="tag">linux</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/mysql/" rel="tag">mysql</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/redis/" rel="tag">redis</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/windows/" rel="tag">windows</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E5%8D%9A%E5%AE%A2%E6%90%AD%E5%BB%BA/" rel="tag">博客搭建</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E6%9C%8D%E5%8A%A1%E5%99%A8/" rel="tag">服务器</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E7%BD%91%E7%BB%9C/" rel="tag">网络</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E8%AF%BB%E4%B9%A6%E7%AC%94%E8%AE%B0/" rel="tag">读书笔记</a></li></ul>
    </div>
  </div>


  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Tag Cloud</h3>
    <div class="widget tagcloud">
      <a href="/tags/JetsonNano/" style="font-size: 10px;">JetsonNano</a> <a href="/tags/Kinect/" style="font-size: 10px;">Kinect</a> <a href="/tags/frp/" style="font-size: 10px;">frp</a> <a href="/tags/hexo/" style="font-size: 10px;">hexo</a> <a href="/tags/linux/" style="font-size: 10px;">linux</a> <a href="/tags/mysql/" style="font-size: 10px;">mysql</a> <a href="/tags/redis/" style="font-size: 10px;">redis</a> <a href="/tags/windows/" style="font-size: 10px;">windows</a> <a href="/tags/%E5%8D%9A%E5%AE%A2%E6%90%AD%E5%BB%BA/" style="font-size: 10px;">博客搭建</a> <a href="/tags/%E6%9C%8D%E5%8A%A1%E5%99%A8/" style="font-size: 15px;">服务器</a> <a href="/tags/%E7%BD%91%E7%BB%9C/" style="font-size: 10px;">网络</a> <a href="/tags/%E8%AF%BB%E4%B9%A6%E7%AC%94%E8%AE%B0/" style="font-size: 20px;">读书笔记</a>
    </div>
  </div>

  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Archives</h3>
    <div class="widget">
      <ul class="archive-list"><li class="archive-list-item"><a class="archive-list-link" href="/archives/2021/12/">December 2021</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2021/11/">November 2021</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2021/10/">October 2021</a></li></ul>
    </div>
  </div>


  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Recent Posts</h3>
    <div class="widget">
      <ul>
        
          <li>
            <a href="/2021/12/08/%E5%BC%A0%E7%BE%8E%E4%B8%BD/">张美丽</a>
          </li>
        
          <li>
            <a href="/2021/12/08/%E9%9D%92%E9%9D%92/">青青</a>
          </li>
        
          <li>
            <a href="/2021/12/08/%E5%B0%8F%E5%BC%A0%E5%92%8C%E5%B0%8F%E4%B8%BD/">小张和小丽</a>
          </li>
        
          <li>
            <a href="/2021/11/24/%E5%91%90%E5%96%8A/">呐喊</a>
          </li>
        
          <li>
            <a href="/2021/11/24/%E9%87%8E%E8%8D%89/">野草</a>
          </li>
        
      </ul>
    </div>
  </div>

  
</aside>
        
      </div>
      <footer id="footer">
  
  <div class="outer">
    <div id="footer-info" class="inner">
      
      &copy; 2021 John Doe<br>
      Powered by <a href="https://hexo.io/" target="_blank">Hexo</a>
    </div>
  </div>
</footer>

    </div>
    <nav id="mobile-nav">
  
    <a href="/" class="mobile-nav-link">Home</a>
  
    <a href="/archives" class="mobile-nav-link">Archives</a>
  
</nav>
    


<script src="/js/jquery-3.4.1.min.js"></script>



  
<script src="/fancybox/jquery.fancybox.min.js"></script>




<script src="/js/script.js"></script>





  </div>
</body>
</html>